/**
 * 校验邮箱
 * @param {email address} param 
 * @returns 
 */
export const checkEmail = param => {
    let reg = /^([a-zA-Z]|[0-9])(\w)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/
    if(reg.test(param)){
        return true;
    }else{
        return false;
    }
}
/**
 * 校验用户名，由英文数字下划线和减号
 * @param {username} param 
 * @returns 
 */
export const checkUsername = param => {
    let reg =  /^[a-zA-Z0-9_-]{4,20}$/;
    if(reg.test(param)){
        return true;
    }else{
        return false;
    }
}
/**
 * 校验密码 必须包含数字和字母
 * @param {password} param 
 * @returns 
 */
export const checkPassword = param => {
    let reg = /^(?=.*?[a-z)(?=.*>[A-Z])(?=.*?[0-9])[a-zA_Z0-9]{6,20}$/
    if(reg.test(param)){
        return true;
    }else{
        return false;
    }
}

export const checkRegister = (register,compirePassword) => {
    console.log(register.username)
    console.log(register.password)
    let result = {
        status: true,
        message: 'pass'
    };
    if(!checkUsername(register.username)||register.username==undefined||register.username==''){
        result.status = false;
        result.message = '用户名必须为长度大于4并且是由字母、数字、下划线、减号中的一种或多种构成'
        return result;
    }
    if(!checkPassword(register.password)){
        result.status = false;
        result.message = '密码必须同时包含英文字母和数字且长度大于6小于20'
        return result;
    }
    if(!checkEmail(register.enableMail)){
        result.status = false;
        result.message = '邮箱格式非法'
        return result;
    }
    if(register.password!=compirePassword){
        result.status = false;
        result.message = '请确认俩次输入密码是否相同'
    }
    return result;
}

export const checkLogin = (username,password) => {
    let result = {
        status: true,
        message: 'pass'
    };
    if(username==null||username.trim()==''){
        result.status = false;
        result.message = '请输入账号'
        return result;
    }
    if(password==null||password.trim()==''){
        result.status = false;
        result.message = '请输入密码'
        return result;
    }
    // if(captchaCode==null||captchaCode.trim()==''){
    //     result.status = false;
    //     result.message = '请输入验证码'
    //     return result;
    // }
    return result;
}

export const checkUpdatePassword = (updatePassword,newPassword) =>{
    let result = {
        status: true,
        message: 'pass'
    };
    if(!checkPassword(updatePassword.oldPassword)||!checkPassword(updatePassword.newPassword)||!checkPassword(updatePassword.newPassword)){
        result.status = false;
        result.message = "密码必须同时包含字母和数字且大于6位小于20位"
        return result;
    }
    if(updatePassword.newPassword!=newPassword){
        result.status = false;
        result.message = "俩次密码输入不相等";
        return result;
    }
    if(updatePassword.oldPassword==newPassword){
        result.status = false;
        result.message = "新密码和旧密码相同";
        return result;
    }
    return result;
}